package android.lollapalooza;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import entities.Band;
import entities.Event;
import entities.Venue;
import org.jsoup.Jsoup;
import service.LollaService;
import service.LollaServiceImpl;

import java.util.ArrayList;
import java.util.List;

public class VenueView extends Activity {

	private LollaService mService;
	private TextView mName;
	private TextView mDescription;
	private TextView mBands;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.venueview);
		mService = new LollaServiceImpl(
				getApplicationContext());

		mName = (TextView) this.findViewById(R.id.name);
		mDescription = (TextView) this.findViewById(R.id.description);
		mBands = (TextView) this.findViewById(R.id.bands);

		Bundle extras = getIntent().getExtras();
		String name = extras.getString("NAME");
		mName.setText(name);

		Venue venue = (Venue) mService.getByName(name, Venue.class);
		String descrip = venue.getDescription();
		if (descrip != null)
			mDescription.setText(Jsoup.parse(descrip).text());
		List<Event> events = mService.getEventsByVenue(venue);

		List<Band> bands = new ArrayList<Band>();
		if (events != null) {
			for (Event event : events)
				 bands.addAll(mService.getBandsByEvent(event));
		}
		
		mBands.setText("Artists\n\n");
		for (Band band : bands) {
			mBands.append(band.getTitle() + "\n");
		}
		
	}

}
